import numpy as np


class Map:
    def __init__(self, ids: np.ndarray = np.array([]), features: np.ndarray = np.array([])) -> None:
        super().__init__()

        self._ids = ids
        self._ids = self._ids.astype(int)
        self._features = features

    def get_ids(self):
        return self._ids

    def is_in(self, id_: int):
        return np.isin(id_, self._ids)

    def get_index(self, id_):
        return np.argmax(self._ids == id_)

    def get_feature(self, id_: int):
        index = self.get_index(id_)
        return self._features[index, :]

    def get_features(self):
        return self._features

    def add(self, id_, feature: np.ndarray):
        self._ids = np.hstack((self._ids, id_))
        if self._features.size == 0:
            self._features = feature.reshape(1, -1)
        else:
            self._features = np.vstack((self._features, feature))

    def update(self, features: np.ndarray):
        self._features[:, :] = features

    def count(self):
        return self._features.shape[0]
